#@admin_header()
<!-- 内容主体区域 -->
<div class="layui-body">
  <div style="padding: 15px;">
    <div class="layui-row">
      <button title="返回" onclick="javascript:;window.history.go(-1);" class="layui-btn">
        <i class="layui-icon">&#xe65c;</i>返回
      </button>
    </div>
    <div class="layui-row">
      <div class="layui-col-md12">
        <fieldset class="layui-elem-field layui-field-title">
          <legend>#(diary==null?'增加收录':'修改收录')</legend>
        </fieldset>
        <form class="layui-form layui-form-pane">
          #(diary==null?'':'<input type="hidden" name="id" value="'+diary.id+'">')
          <div class="layui-form-item">
            <label class="layui-form-label">出自</label>
            <div class="layui-input-block">
              <input type="text" name="author" value="#(diary.author??)" autocomplete="off" placeholder="一本书或者某个人"
                     class="layui-input">
            </div>
          </div>
          <div class="layui-form-item">
            <label class="layui-form-label">备注</label>
            <div class="layui-input-block">
              <input type="text" name="remark" value="#(diary.remark??)" autocomplete="off" placeholder="是哪本书或者哪个时间、地点"
                     class="layui-input">
            </div>
          </div>
          <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">收录内容</label>
            <div class="layui-input-block">
              <textarea name="content" onkeyup="contentListener()" placeholder="请输入内容" class="layui-textarea">#(diary.content??)</textarea>
            </div>
          </div>
          <div class="layui-form-item">
            <div class="layui-input-block">
              <button class="layui-btn" lay-submit="" lay-filter="contentDiary">立即提交</button>
              <button type="reset" onclick="test()" class="layui-btn layui-btn-primary">重置</button>
            </div>
          </div>
        </form>
      </div>
    </div>
  </div>
</div>
<script type="text/javascript">
  //JavaScript代码区域
  layui.use('form', function () {
    var form = layui.form;
    // 提交
    form.on('submit(contentDiary)', function (data) {
      if (isBlank($('[name=content]').val())) {
        ToastWarn('收录内容不能为空');
        $('[name=content]').focus();
        return false;
      }
      ToastLoading('正在保存...');
      $.ajax({
        url: "#(postUrl)",
        type: "post",
        data: data.field,
        success: function (ret) {
          ToastShow(ret.code, ret.msg, ret.url);
        },
        error: function (ret) {
          ToastErr('网络错误');
        }
      });
      return false;
    });
  });

  /**
   * 输入内容监听
   * @return {[type]} [description]
   */
  function contentListener() {
    var content = $('[name=content]').val();
    if (content.length > 200) {
      ToastInfo('不建议在这里写文章');
    }
  }
</script>
#@admin_footer()
